
new Vue({
    el: '#app',
    delimiters:['[[', ']]'],

    data: {
        replies: [],
    },

    methods: {
        /**
         * 请求快速回复列表
         */
        requestFastReplyList() {
            let url = "{% url 'gma:api_get_fast_reply_list' %}";
            new my_ajax(url, {}, '', '', (data) => {
                console.table(data);
                this.replies = data;

                this.replies.forEach(reply => {
                    reply.edit_url = `/gma/config/fast_reply/${reply.fast_reply_id}/edit/`;
                });
            });
        },

        /**
         * 点击快速回复
         * @param reply
         */
        clickFastReply(reply) {
            if (reply.enabled === 1) {
                this.disableFastReply(reply.fast_reply_id);
            } else {
                this.enableFastReply(reply.fast_reply_id);
            }
        },

        /**
         * 启用快速回复
         *
         * @param fast_reply_id
         */
        enableFastReply(fast_reply_id) {
            let data = {
                'fast_reply_id': fast_reply_id,
            };

            let url = "{% url 'gma:api_enable_fast_reply' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功开启');
                this.requestFastReplyList();
            });
        },

        /**
         * 禁用快速回复
         *
         * @param fast_reply_id
         */
        disableFastReply(fast_reply_id) {
            let data = {
                'fast_reply_id': fast_reply_id,
            };

            let url = "{% url 'gma:api_disable_fast_reply' %}";
            new my_ajax(url, data, '', '', () => {
                show_toast('成功关闭');
                this.requestFastReplyList();
            });
        },
    },

    mounted() {
        this.requestFastReplyList();
    },
});
